# coding=utf-8

"""
    Created by Kalyter on 2017-11-23.
"""


from matplotlib import pyplot as plt
import numpy as np
from math import ceil

# 高斯分布
mean = [0, 0]
cov = [[0, 1], [1, 0]]
x, y = np.random.multivariate_normal(mean, cov, 10000).T
hist, xedges, yedges = np.histogram2d(x, y)


def histogram2d():
    plt.imshow(hist)
    plt.grid(True)
    plt.colorbar()
    plt.show()


def grid():
    plt.hist2d(x, y, bins=40)
    plt.colorbar()
    plt.grid()
    plt.show()


def nearest():
    plt.imshow(hist, interpolation='nearest')
    plt.grid(True)
    plt.colorbar()
    plt.show()


def pcolor():
    plt.pcolor(hist)
    plt.colorbar()
    plt.grid()
    plt.show()


def mat_show():
    columns = ['A', 'B', 'C', 'D']
    rows = ['1', '2', '3', '4']

    data = np.random.random((4, 4))

    fig = plt.figure()

    ax = fig.add_subplot(111)

    cax = ax.matshow(data, interpolation='nearest')
    fig.colorbar(cax)

    ax.set_xticklabels([''] + columns)
    ax.set_yticklabels([''] + rows)

    plt.show()


def random_plot():
    # 高斯分布
    mean = [0, 0]
    cov = [[0, 1], [1, 0]]
    x, y = np.random.multivariate_normal(mean, cov, 100).T

    size = len(plt.cm.datad.keys())
    all_maps = list(plt.cm.datad.keys())

    fig, ax = plt.subplots(ceil(size / 4), 4, figsize=(12, 100))

    counter = 0
    for row in ax:
        for col in row:
            try:
                col.imshow(hist, cmap=all_maps[counter])
                col.set_title(all_maps[counter])
            except IndexError:
                break
            counter += 1

    plt.tight_layout()
    plt.show()


if __name__ == '__main__':
    mat_show()
